package LeetCode;

/**
 * 11. 盛最多水的容器
 * https://leetcode.cn/problems/container-with-most-water/description/
 */
class Solution2 {
    public int maxArea(int[] height) {
        int left = 0;
        int right = height.length - 1;
        int ret = 0;
        while(left < right) {
            int h = Math.min(height[left], height[right]);
            int v = h * (right - left);
            ret = Math.max(ret, v);
            if(height[left] > height[right]) {
                right--;
            } else {
                //height[left] <= height[right]
                left++;
            }
        }
        return ret;
    }
}